package com.tarena.lbs.coupon.dao.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tarena.lbs.coupon.dao.mapper.StockMapper;
import com.tarena.lbs.coupon.dao.repository.StockRepository;
import com.tarena.lbs.coupon.pojo.po.CouponStockPO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class StockRepositoryImpl implements StockRepository {

    @Autowired
    private StockMapper stockMapper;

    @Override
    public void saveStock(CouponStockPO couponStockPO) {
        stockMapper.insert(couponStockPO);
    }

    @Override
    public void deleteByCouponId(Integer id) {
        // 构建查询条件
        QueryWrapper<CouponStockPO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("coupon_id", id);
        // 执行删除操作
        stockMapper.delete(queryWrapper);
    }

    @Override
    public CouponStockPO selectByCouponId(Integer couponId) {
        // 构建查询条件
        QueryWrapper<CouponStockPO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("coupon_id", couponId);
        // 执行查询操作
        return stockMapper.selectOne(queryWrapper);
    }
}
